package com.cwd.arm.common.encoder;

import com.cwd.arm.common.constant.SysConstant;
import com.cwd.arm.common.util.Md5Util;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * Created by yan on 22-1-1.
 */
public class ArmPasswordEncoder implements PasswordEncoder {

    private static ArmPasswordEncoder instance = new ArmPasswordEncoder();

    private String mask;

    public static ArmPasswordEncoder getInstance() {
        return instance;
    }

    public static String getInitPassword(String password,String mask) {
        return Md5Util.getMD5Str(password + "_" + mask);
    }


    @Override
    public String encode(CharSequence charSequence) {
        return Md5Util.getMD5Str(getMaskPassword(charSequence));
    }

    @Override
    public boolean matches(CharSequence charSequence, String s) {
        return s.equals(encode(charSequence));
    }


    public void setMask(String mask) {
        this.mask = mask;
    }

    private String getMaskPassword(CharSequence charSequence) {
        return charSequence + "_" + mask;
    }


}
